package com.ruoyi.framework.config;

import com.aliyun.dysmsapi20170525.Client;
import com.ruoyi.framework.config.properties.SmsAliyunProperties;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
@EnableConfigurationProperties(SmsAliyunProperties.class)
public class SmsConfig {

    @Autowired
    private SmsAliyunProperties smsAliyunProperties;

    /**
     * 注入阿里云短信客户端
     * @return
     * @throws Exception
     */
    @Bean
    public Client client() throws Exception {
        com.aliyun.teaopenapi.models.Config config = new com.aliyun.teaopenapi.models.Config()
                // 必填，您的 AccessKey ID
                .setAccessKeyId(smsAliyunProperties.getAccessKeyId())
                // 必填，您的 AccessKey Secret
                .setAccessKeySecret(smsAliyunProperties.getAccessKeySecret());
        return new Client(config);
    }
}
